package com.xtx.air.web.action.login;


import com.google.code.jcaptcha4struts2.common.actions.JCaptchaBaseAction;
import com.xtx.air.bo.user.IUserBO;
import com.xtx.air.dataobject.UserDO;
import com.xtx.air.web.action.BaseAction;
import com.xtx.util.StringUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import java.util.List;

public class RegisterAction extends JCaptchaBaseAction {
    protected Log logger = LogFactory.getLog(this.getClass());
    private UserDO user = new UserDO();
    private IUserBO userBO;

    public String reg() {
        return SUCCESS;
    }

    public String doReg() {
        try {
            userBO.addUser(user);
        } catch (Exception e) {
            logger.error("注册失败", e);
            addActionError("注册失败:" + e.getMessage());
            return INPUT;
        }
        return SUCCESS;
    }

    public String logoff() {
        Subject currentUser = SecurityUtils.getSubject();
        currentUser.logout();
        return SUCCESS;
    }

    public UserDO getUser() {
        return user;
    }

    public void setUser(UserDO user) {
        this.user = user;
    }

    public IUserBO getUserBO() {
        return userBO;
    }

    public void setUserBO(IUserBO userBO) {
        this.userBO = userBO;
    }
}
